package com.gxa.service.investment.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.dto.investmentDto.ProjectDto;
import com.gxa.entity.investment.Project;
import com.gxa.mapper.investment.ProjectMapper;
import com.gxa.service.investment.ProjectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 项目管理——项目公海——新增项目 服务实现类
 * </p>
 *
 * @author yjl
 * @since 2022-10-17 03:04:36
 */
@Service
public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> implements ProjectService {
    @Autowired
    private ProjectMapper projectMapper;

    @Override
    public int add(Project project) {
        return projectMapper.insert(project);
    }

    @Override
    public int delete(Integer id) {
        return projectMapper.deleteById(id);
    }

    @Override
    public Project queryById(Integer id) {
        return projectMapper.selectById(id);
    }

    @Override
    public PageInfo seletAll(Integer pageNum,Integer pageSize) {
        Page<Project> page1 = PageHelper.startPage(pageNum,pageSize);
        List<Project> exchangeRecordDtos = this.projectMapper.selectList(null);
        PageInfo<Project> pageInfo = new PageInfo<Project>(exchangeRecordDtos);
        return pageInfo;
    }

    @Override
    public int update(Project project) {
        return projectMapper.updateById(project);
    }

    @Override
    public void updatePlanId(Integer id) {
        this.projectMapper.updatePlanId(id);
    }

    @Override
    public PageInfo<Project> queryByCondition(ProjectDto projectDto,Integer pageNum,Integer pageSize) {
        LambdaQueryWrapper<Project> lqw = new LambdaQueryWrapper<>();
        //等于
        if (null != projectDto.getProjectName()){
            lqw.eq(Project::getProjectName,projectDto.getProjectName());
        }

        if (null != projectDto.getBusiness()){
            lqw.eq(Project::getBusiness,projectDto.getBusiness());
        }

        if (null != projectDto.getSourceWay()){
            lqw.eq(Project::getSourceWay, projectDto.getSourceWay());
        }
        //大于
        if (null != projectDto.getStartTime()){
            lqw.ge(Project::getCreationTime,projectDto.getStartTime());
        }
        //小于
        if(null != projectDto.getEndTime()){
            lqw.le(Project::getCreationTime,projectDto.getEndTime());
        }
        Page<Project> page1 = PageHelper.startPage(pageNum,pageSize);
        List<Project> exchangeRecordDtos = this.projectMapper.selectList(lqw);
        PageInfo<Project> pageInfo = new PageInfo<Project>(exchangeRecordDtos);

        return pageInfo;
    }

}
